package db;

import pojo.*;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DataBase {
    private List<User> usersList = new ArrayList<>();
    private List<Car> carsList = new ArrayList<>();
    private List<Brand> brandsList = new ArrayList<>();
    private List<CarType> carTypesList = new ArrayList<>();
    private Map<User,Collect> collectsList = new HashMap<>();
    private Map<User,Contrast> contrastsList = new HashMap<>();

    private static DataBase dataBase = new DataBase();
    private DataBase() {
        //  1 --- 为上述集合添加一些初始的数据 不可使用list.of()

        //品牌-brand
        Brand brand1 = new Brand(1,"大众", "日本生产");
        Brand brand2 = new Brand(2,"雪佛兰", "英国生产");
        Brand brand3 = new Brand(3,"福特", "美国生产");
        Brand brand4 = new Brand(4,"斯柯达", "美国生产");
        Brand brand5 = new Brand(5,"奔驰", "德国生产");
        Brand brand6 = new Brand(6,"宝马", "德国生产");
        Brand brand7 = new Brand(7,"法拉利", "德国生产");
        Brand brand8 = new Brand(8,"保时捷", "美国生产");
        Brand brand9 = new Brand(9,"别克", "日本生产");
        brandsList.add(brand1);
        brandsList.add(brand2);
        brandsList.add(brand3);
        brandsList.add(brand4);
        brandsList.add(brand5);
        brandsList.add(brand6);
        brandsList.add(brand7);
        brandsList.add(brand8);
        brandsList.add(brand9);


        //车型-CarType
        CarType carType1 = new CarType("1", "桑塔纳");
        CarType carType2 = new CarType("2", "科鲁兹");
        CarType carType3 = new CarType("3", "速腾");
        CarType carType4 = new CarType("4", "帕萨特");
        carTypesList.add(carType1);
        carTypesList.add(carType2);
        carTypesList.add(carType3);
        carTypesList.add(carType4);

        //车 - Car
        Car car1 = new Car("1", 2, LocalDate.parse("2010-11-22", DateTimeFormatter.ofPattern("yyyy-MM-dd")),65000, 32000, "自动挡",LocalDate.parse("2010-12-22", DateTimeFormatter.ofPattern("yyyy-MM-dd")), brand1, carType1);
        Car car2 = new Car("2", 1.5, LocalDate.parse("2011-01-22", DateTimeFormatter.ofPattern("yyyy-MM-dd")),75000, 3000, "手自一体",LocalDate.parse("2010-02-25", DateTimeFormatter.ofPattern("yyyy-MM-dd")), brand2, carType2);
        Car car3 = new Car("3", 2, LocalDate.parse("2015-01-02", DateTimeFormatter.ofPattern("yyyy-MM-dd")),100000, 23000, "自动挡",LocalDate.parse("2015-02-02", DateTimeFormatter.ofPattern("yyyy-MM-dd")), brand3, carType3);
        Car car4 = new Car("4", 1.5, LocalDate.parse("2005-06-02", DateTimeFormatter.ofPattern("yyyy-MM-dd")),100000, 25000, "手自一体",LocalDate.parse("2005-07-02", DateTimeFormatter.ofPattern("yyyy-MM-dd")), brand4, carType4);
        Car car5 = new Car("5", 2, LocalDate.parse("2000-09-02", DateTimeFormatter.ofPattern("yyyy-MM-dd")),100000, 50000, "自动挡",LocalDate.parse("2000-09-12", DateTimeFormatter.ofPattern("yyyy-MM-dd")), brand5, carType1);
        Car car6 = new Car("6", 1.5, LocalDate.parse("1999-09-02", DateTimeFormatter.ofPattern("yyyy-MM-dd")),100000, 35000, "自动挡", LocalDate.parse("1999-12-12", DateTimeFormatter.ofPattern("yyyy-MM-dd")),brand6, carType2);
        Car car7 = new Car("7", 3, LocalDate.parse("2008-09-02", DateTimeFormatter.ofPattern("yyyy-MM-dd")),100000, 23000, "手自一体",LocalDate.parse("2009-09-12", DateTimeFormatter.ofPattern("yyyy-MM-dd")), brand7, carType3);
        Car car8 = new Car("8", 1.5, LocalDate.parse("2011-09-02", DateTimeFormatter.ofPattern("yyyy-MM-dd")),100000, 3000, "自动挡",LocalDate.parse("2012-03-12", DateTimeFormatter.ofPattern("yyyy-MM-dd")), brand8, carType4);
        Car car9 = new Car("9", 2, LocalDate.parse("2004-09-02", DateTimeFormatter.ofPattern("yyyy-MM-dd")),100000, 23000, "手自一体",LocalDate.parse("2004-09-12", DateTimeFormatter.ofPattern("yyyy-MM-dd")), brand9, carType2);
        Car car10 = new Car("10", 1.5, LocalDate.parse("2003-12-02", DateTimeFormatter.ofPattern("yyyy-MM-dd")),100000, 23000, "手自一体", LocalDate.parse("2015-04-12", DateTimeFormatter.ofPattern("yyyy-MM-dd")),brand7, carType1);
        Car car11 = new Car("11", 2, LocalDate.parse("2006-09-02", DateTimeFormatter.ofPattern("yyyy-MM-dd")),100000, 23000, "手自一体",LocalDate.parse("2007-06-29", DateTimeFormatter.ofPattern("yyyy-MM-dd")), brand9, carType3);
        Car car12 = new Car("12", 3, LocalDate.parse("2018-09-02", DateTimeFormatter.ofPattern("yyyy-MM-dd")),100000, 23000, "手自一体", LocalDate.parse("2022-09-12", DateTimeFormatter.ofPattern("yyyy-MM-dd")),brand8, carType4);
        carsList.add(car1);
        carsList.add(car2);
        carsList.add(car3);
        carsList.add(car4);
        carsList.add(car5);
        carsList.add(car6);
        carsList.add(car7);
        carsList.add(car8);
        carsList.add(car9);
        carsList.add(car10);
        carsList.add(car11);
        carsList.add(car12);

        //用户
        User user1 = new User("matter","123" ,0,new BigDecimal(1111));
        User user2 = new User("faker","1314" ,1,new BigDecimal(22222));
        User user3 = new User("clide","1122" ,2,new BigDecimal(3333));
        User user4 = new User("theshy","2222" ,0,new BigDecimal(4444));
        User user5 = new User("xiaoxiang","2221" ,1,new BigDecimal(5555));
        User user6 = new User("makera","2211" ,2,new BigDecimal(6666));
        User user7 = new User("doinb","2255" ,0,new BigDecimal(7777));
        User user8 = new User("lwx","2254" ,1,new BigDecimal(8888));
        User user9 = new User("crisp","1587" ,2,new BigDecimal(9999));
        usersList.add(user1);
        usersList.add(user2);
        usersList.add(user3);
        usersList.add(user4);
        usersList.add(user5);
        usersList.add(user6);
        usersList.add(user7);
        usersList.add(user8);
        usersList.add(user9);

        //默认 收藏集合、对比集合为空
    }
    public static DataBase getInstance(){
        return dataBase;
    }

    public List<User> getUsersList() {
        return usersList;
    }

    public List<Car> getCarsList() {
        return carsList;
    }

    public List<Brand> getBrandsList() {
        return brandsList;
    }

    public List<CarType> getCarTypesList() {
        return carTypesList;
    }

    public Map<User,Collect> getCollectsMap() {
        return collectsList;
    }


    public Map<User,Contrast> getContrastsMap() {
        return contrastsList;
    }

}
